<template>
  <el-dialog :title="title" :visible.sync="dialogTableVisible">
    <el-table :data="logs" v-loading="loading">
      <el-table-column type="expand">
        <template slot-scope="props">
          <div>
            <pre style="text-align: initial">
              {{props.row.result ? props.row.result : '没有执行结果'}}
            </pre>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="id" label="ID" width="80"></el-table-column>
      <el-table-column prop="create_time" label="日期"></el-table-column>
      <el-table-column prop="name" label="命令名称"></el-table-column>
      <el-table-column prop="command" label="命令内容">
        <template slot-scope="scope">
          {{scope.row.command ? scope.row.command : '-'}}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.status === 1 ? 'success' : scope.row.status === -1 ?  'warning' : 'info'">
            {{scope.row.status === 1 ? '成功' : scope.row.status === -1 ?  '失败' : '已发送'}}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>
import Common from '@/api/Common'
const _http = new Common()
export default {
  data () {
    return {
      title: '',
      dialogTableVisible: false,
      loading: true,
      logs: [],
      form: {
        device_number: null
      }
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.$on('dialogLog', (res) => {
        console.log('wat', res)
        this.dialogTableVisible = true
        this.title = res.class_room
        this.form.device_number = res.device_number
        this.logs = []
        this.loading = true
        this.getCommandsList()
      })
    })
  },
  created () {
  },
  methods: {
    getCommandsList () {
      _http.get('/control/telnet/getLogs', this.form).then(res => {
        console.log('logs', res)
        if (res.status === 1) {
          this.logs = res.data
        } else {
          this.$message.error(res.msg)
        }
        this.loading = false
      }).catch(error => {
        console.log('err', error)
        this.loading = false
      })
    },
    sendCommand (row) {
      console.log('send', row)
    }
  }
}
</script>
